package org.lisen.patterndemo.chain.v01;

import org.lisen.patterndemo.chain.Message;

import java.util.ArrayList;
import java.util.List;

/**
 * 将Filter组织成一个链条
 */
public class FilterChain {

    private FilterChain(){}

    private static List<Filter> filters = new ArrayList<>();

    private static FilterChain instance = new FilterChain();

    public static FilterChain getInstance(){
        return instance;
    }

    public FilterChain add(Filter filter) {
        filters.add(filter);
        return this;
    }

    public Message dofilters(final Message message) {
        filters.forEach(f -> {
            f.doFilter(message);
        });
        return message;
    }

}
